from rest_framework import permissions

class IsOwerReadOnly(permissions.BasePermission):
    """自定义权限：只允许对象的所有者能够编辑"""
    #重写has_object_permission(self, request, view,obj)
    def has_object_permission(self, request, view,obj):
        """

        :param request:
        :param view:
        :param obj:
        :return:boolean
        """
        if request.method in permissions.SAFE_METHODS:
            return True
        #对象的所有者才有写权限
        return obj.teacher==request.user